home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / logiso.000 / logiso / RCS / ioctl.c,v < prev    next >
Encoding:
Text File  |  1995-03-24  |  10.3 KB  |  461 lines

  1. head    1.8;
  2. access;
  3. symbols
  4.     VER_0_3:1.8
  5.     VER_0_2:1.7;
  6. locks; strict;
  7. comment    @ * @;
  8.  
  9.  
  10. 1.8
  11. date    95.03.24.11.44.17;    author coulter;    state Exp;
  12. branches;
  13. next    1.7;
  14.  
  15. 1.7
  16. date    95.03.10.02.43.06;    author coulter;    state Exp;
  17. branches;
  18. next    1.6;
  19.  
  20. 1.6
  21. date    95.02.19.17.15.09;    author coulter;    state Exp;
  22. branches;
  23. next    1.5;
  24.  
  25. 1.5
  26. date    95.02.18.09.21.50;    author coulter;    state Exp;
  27. branches;
  28. next    1.4;
  29.  
  30. 1.4
  31. date    95.02.14.21.39.21;    author coulter;    state Exp;
  32. branches;
  33. next    1.3;
  34.  
  35. 1.3
  36. date    95.02.14.20.22.40;    author coulter;    state Exp;
  37. branches;
  38. next    1.2;
  39.  
  40. 1.2
  41. date    95.02.13.20.56.00;    author coulter;    state Exp;
  42. branches;
  43. next    1.1;
  44.  
  45. 1.1
  46. date    95.02.11.13.14.47;    author coulter;    state Exp;
  47. branches;
  48. next    ;
  49.  
  50.  
  51. desc
  52. @Define iso_ioctl.  Will define ioctl commands for logging.
  53. @
  54.  
  55.  
  56. 1.8
  57. log
  58. @Checkin version for 0.3 distribution.
  59. @
  60. text
  61. @/*
  62.  * linux/fs/isofs/ioctl.c - ioctl stuff to log operations
  63.  * 
  64.  *  (C) Copyright 1995 by Michael Coulter.  All rights reserved.
  65.  *
  66.  */
  67.  
  68. #include <asm/segment.h>
  69.  
  70. #include <linux/errno.h>
  71. #include <linux/fs.h>
  72. #include <linux/iso_fs.h>
  73. #include <linux/ioctl.h>
  74. #include <linux/kernel.h>
  75. #include <linux/malloc.h>
  76. #include <linux/sched.h>
  77.  
  78. /****************************************************************************
  79.   Local defines for logging:
  80.     ISO_LOG_MALLOC_LIMIT    largest region obtainable from kmalloc()
  81.     ISO_LOG_ENTRIES_PER_BUF    The number of log entries that fit in a buffer.
  82.     ISO_LOG_NBR_LOG_BUFS    The number of ISO_LOG_MALLOC_LIMIT size buffers
  83.                 to allocate to hold log information.
  84.     ISO_LOG_SIZE        Size of memory passed to user.  iso_log_info
  85.                 plus space for all the buffers.
  86. ****************************************************************************/
  87.  
  88. /* Define ISO_LOG_MALLOC_LIMIT  for use in another define */
  89. #define ISO_LOG_MALLOC_LIMIT        4096
  90.  
  91.  
  92.  
  93. #define ISO_LOG_ENTRIES_PER_BUF     (  ISO_LOG_MALLOC_LIMIT     \
  94.                       / sizeof(struct iso_log_entry))
  95. #define ISO_LOG_NBR_LOG_BUFS        10
  96. #define ISO_LOG_SIZE            (   sizeof(struct iso_log_info) \
  97.                       + (  ISO_LOG_NBR_LOG_BUFS     \
  98.                          * ISO_LOG_MALLOC_LIMIT))
  99.  
  100. /****************************************************************************
  101.    Data declarations
  102. ****************************************************************************/
  103.  
  104. static struct iso_log_info    iso_log_pass;
  105. static int            iso_overflow_count;
  106.  
  107. static int            log_buf_index;
  108. static int             iso_log_is_active = 1;
  109. static struct iso_log_entry*    log_buffers[ISO_LOG_NBR_LOG_BUFS];
  110.  
  111. /* If first_log_p is NULL, iso_initialize_log must be called. */
  112.  
  113. static struct iso_log_entry*    first_log_p = NULL; 
  114. static struct iso_log_entry*    limit_log_p;
  115. static struct iso_log_entry*    next_log_p;
  116.  
  117. /****************************************************************************
  118.    iso_stop_log - stop logging.  Free log buffers.
  119. ****************************************************************************/
  120.  
  121. static void iso_stop_log(void) {
  122.    int idx;
  123.  
  124.    iso_log_is_active = 0;
  125.    if (first_log_p == NULL) {
  126.       return;  /* Nothing to free */
  127.    }
  128.    for (idx = 0;  idx < ISO_LOG_NBR_LOG_BUFS;  idx++) {
  129.        kfree_s(log_buffers[idx], ISO_LOG_MALLOC_LIMIT);
  130.    }
  131.    first_log_p = NULL;
  132. } /* end iso_stop_log */
  133.  
  134.  
  135.  
  136. /****************************************************************************
  137.    iso_initialize_log: Initialize logging.  Allocate log buffers 
  138.                   Return TRUE if success.
  139. ****************************************************************************/
  140.  
  141. static int iso_initialize_log(void)
  142. {
  143.    int idx;
  144.  
  145.    /* Define entire array of log_buffers in case we must bail out and
  146.    ** call iso_stop_log.
  147.    */
  148.    for (idx = 0;  idx < ISO_LOG_NBR_LOG_BUFS;  idx++) {
  149.        log_buffers[idx] = NULL;
  150.    }
  151.    for (idx = 0;  idx < ISO_LOG_NBR_LOG_BUFS;  idx++) {
  152.       if (    (log_buffers[idx] = (struct iso_log_entry*) 
  153.                   kmalloc(ISO_LOG_MALLOC_LIMIT, GFP_KERNEL)) 
  154.            == NULL) 
  155.       {
  156.      first_log_p = log_buffers[0];
  157.      iso_stop_log();
  158.      return 0;  /* Failure to initialize log */
  159.       } 
  160.    }
  161.    log_buf_index = 0;
  162.    iso_overflow_count = 0;
  163.    first_log_p = log_buffers[0];
  164.    next_log_p = first_log_p;
  165.    limit_log_p = first_log_p + ISO_LOG_ENTRIES_PER_BUF;
  166.    iso_log_is_active = 1;
  167.    return 1; /* success, TRUE */
  168. } /* end iso_initialize_log */
  169.  
  170.  
  171. /****************************************************************************
  172.     next_buffer - Move first_log_p to the next buffer. 
  173. ****************************************************************************/
  174. static void next_buffer(void)
  175. {
  176.    log_buf_index++;
  177.    if (log_buf_index >= ISO_LOG_NBR_LOG_BUFS) {
  178.       iso_overflow_count++;
  179.       log_buf_index = 0;
  180.    }
  181.    first_log_p = log_buffers[log_buf_index];
  182.    next_log_p = first_log_p;
  183.    limit_log_p = first_log_p + ISO_LOG_ENTRIES_PER_BUF;
  184. } /* end next_buffer */
  185.  
  186.  
  187. /****************************************************************************
  188.    iso_ioctl  - Routine to handle ioctl calls.
  189. ****************************************************************************/
  190.  
  191. int iso_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
  192.         unsigned long arg)
  193. {
  194.    switch (cmd) {
  195.       case ISO_IOC_GETLOGSIZE :
  196.      if (first_log_p == NULL) {
  197.         iso_initialize_log();
  198.      }
  199.      return ISO_LOG_SIZE;
  200.  
  201.       case ISO_IOC_READLOG :
  202.      return iso_log_read(inode, (void *) arg);
  203.  
  204.       case ISO_IOC_STOPLOG :
  205.          iso_stop_log();
  206.          return 0;
  207.  
  208.       default:
  209.      return -EINVAL;
  210.    }
  211.    return -EINVAL;
  212. } /* end iso_ioctl */
  213.  
  214.  
  215. /****************************************************************************
  216.   iso_log_add - Add an entry to the log
  217. ****************************************************************************/
  218.  
  219. void iso_log_add(unsigned long inode, dev_t i_dev, int operation) {
  220.    if (! iso_log_is_active) {
  221.       return;
  222.    }
  223.    if (first_log_p == NULL) {
  224.       if (!iso_initialize_log()) {
  225.          return;
  226.       }
  227.    }
  228.    if (next_log_p == limit_log_p) {
  229.       next_buffer(); /* Move pointers to the next (or first) buffer */
  230.    }
  231.    next_log_p->inode = inode;
  232.    next_log_p->operation = operation;
  233.    next_log_p->device = i_dev;
  234.    next_log_p++;
  235. } /* end iso_log_add */
  236.  
  237.  
  238. /****************************************************************************
  239.    iso_log_read - return the buffer to the caller.  Empty the log.
  240. ****************************************************************************/
  241. int iso_log_read(struct inode * inode, void* user_buf_p)
  242. {
  243.    struct iso_log_entry*    from_ptr;
  244.    int                idx;
  245.    struct iso_log_entry*    to_ptr;
  246.    struct iso_log_info*        user_ptr;
  247.  
  248.    if (first_log_p == NULL) {
  249.       if (!iso_initialize_log()) {
  250.      return -ENOMEM;
  251.       }
  252.    }
  253.    iso_log_pass.version = ISO_LOG_VERSION;
  254.    iso_log_pass.buf_format = ISO_LOG_BUF_FORMAT1;
  255.    iso_log_pass.size = ISO_LOG_SIZE;
  256.    iso_log_pass.device = inode->i_dev;
  257.    iso_log_pass.overflow_count = iso_overflow_count;
  258.    iso_log_pass.nbr_entries =   next_log_p - first_log_p 
  259.                      + (ISO_LOG_ENTRIES_PER_BUF * log_buf_index);
  260.  
  261.    memcpy_tofs(user_buf_p, &iso_log_pass, sizeof(struct iso_log_info));
  262.  
  263.    /* Now copy the log buffers */
  264.  
  265.    user_ptr = (struct iso_log_info*) user_buf_p;
  266.    to_ptr = &(user_ptr->log_entry[0]);
  267.    for (idx = 0;  idx < ISO_LOG_NBR_LOG_BUFS;  idx++) {
  268.       from_ptr = log_buffers[idx];
  269.       memcpy_tofs(to_ptr, 
  270.                   from_ptr, 
  271.                   ISO_LOG_ENTRIES_PER_BUF * sizeof(struct iso_log_entry));
  272.       to_ptr += ISO_LOG_ENTRIES_PER_BUF;
  273.    }
  274.  
  275.    /* reset log */
  276.  
  277.    log_buf_index = ISO_LOG_NBR_LOG_BUFS - 1;
  278.    next_buffer();
  279.    iso_overflow_count = 0;
  280.  
  281.    return 0;
  282. } /* end iso_log_read */
  283.  
  284.  
  285. /****************************************************************************
  286.    log_generic_mmap - possibly log calls to generic_mmap
  287. ****************************************************************************/
  288.  
  289. int     log_generic_mmap(struct inode * inode,
  290.              struct file * file, 
  291.              struct vm_area_struct * vm_area)
  292. {
  293.    /* Reduce log volume by not logging this.  it is 
  294.    ** always? preceeded by other ops. 
  295.    */
  296.    /* iso_log_add(inode->i_ino, inode->i_dev, ISO_LOG_OP_generic_mmap); */
  297.    return generic_mmap(inode, file, vm_area);
  298. } /* end log_generic_mmap */
  299.  
  300. @
  301.  
  302.  
  303. 1.7
  304. log
  305. @Checkin files modified to make version 0.2
  306. @
  307. text
  308. @d3 2
  309. @
  310.  
  311.  
  312. 1.6
  313. log
  314. @Added code to map generic_mmap.  Commented out for now.
  315. @
  316. text
  317. @d140 1
  318. a140 1
  319.      return iso_log_read((void *) arg);
  320. d157 1
  321. a157 1
  322. void iso_log_add(unsigned long inode, int operation) {
  323. d171 1
  324. d179 1
  325. a179 1
  326. int iso_log_read(void* user_buf_p)
  327. d194 1
  328. d234 1
  329. a234 1
  330.    /* iso_log_add(inode->i_ino, ISO_LOG_OP_generic_mmap); */
  331. @
  332.  
  333.  
  334. 1.5
  335. log
  336. @Checkin version 0.1, size, get log, stop
  337. @
  338. text
  339. @d219 17
  340. @
  341.  
  342.  
  343. 1.4
  344. log
  345. @Checkpoint files to send to isofs owners.
  346. @
  347. text
  348. @d64 1
  349. a64 1
  350.       return;  /* Nothing to stop */
  351. @
  352.  
  353.  
  354. 1.3
  355. log
  356. @Checkpoint working dynamic log version.
  357. @
  358. text
  359. @d16 27
  360. a42 1
  361. static struct iso_log_info    iso_log_info;
  362. d55 3
  363. a57 1
  364. /* Stop logging.  Free allocated log buffers. */
  365. d73 5
  366. a77 1
  367. /* Initialize logging.  Allocate log buffers Return TRUE if success. */
  368. d108 4
  369. a111 1
  370. /* Move first_log_p to the next buffer.  */
  371. d124 4
  372. a127 1
  373. /* Routine to handle ioctl calls */
  374. d152 4
  375. a155 1
  376. /* Add an entry to the log */
  377. d174 4
  378. d190 5
  379. a194 5
  380.    iso_log_info.version = ISO_LOG_VERSION;
  381.    iso_log_info.buf_format = ISO_LOG_BUF_FORMAT1;
  382.    iso_log_info.size = ISO_LOG_SIZE;
  383.    iso_log_info.overflow_count = iso_overflow_count;
  384.    iso_log_info.nbr_entries =   next_log_p - first_log_p 
  385. d197 1
  386. a197 1
  387.    memcpy_tofs(user_buf_p, &iso_log_info, sizeof(struct iso_log_info));
  388. @
  389.  
  390.  
  391. 1.2
  392. log
  393. @Checkin working version.  Try to make it dynamic now.
  394. @
  395. text
  396. @d12 2
  397. d17 1
  398. a17 1
  399. static int            iso_overflow_count = 0;
  400. d19 3
  401. a21 4
  402. static struct iso_log_entry*    first_log_p = &iso_log_info.log_entry[0];
  403. static struct iso_log_entry*    limit_log_p = &iso_log_info
  404.                                                 .log_entry[ISO_LOG_MAX_ENTRIES];
  405. static struct iso_log_entry*    next_log_p = &iso_log_info.log_entry[0];
  406. d23 65
  407. d94 19
  408. a112 11
  409.     switch (cmd) {
  410.         case ISO_IOC_GETLOGSIZE :
  411.             return sizeof(struct iso_log_info);
  412.  
  413.         case ISO_IOC_READLOG :
  414.             return iso_log_read((void *) arg);
  415.  
  416.         default:
  417.             return -EINVAL;
  418.     }
  419. }
  420. d117 8
  421. d126 1
  422. a126 3
  423.       /* No more room, reset log */
  424.       iso_overflow_count++;
  425.       next_log_p = first_log_p;
  426. d135 10
  427. d146 2
  428. a147 1
  429.    iso_log_info.size = sizeof(iso_log_info);
  430. d149 2
  431. a150 1
  432.    iso_log_info.nbr_entries = next_log_p - first_log_p;
  433. d153 19
  434. a171 1
  435.    next_log_p = first_log_p; /* reset log */
  436. @
  437.  
  438.  
  439. 1.1
  440. log
  441. @Initial revision
  442. @
  443. text
  444. @d2 1
  445. a2 1
  446.  * linux/fs/isofs/ioctl.c
  447. d14 11
  448. a27 3
  449.     int err;
  450.     unsigned long flags;
  451.  
  452. d29 2
  453. a30 2
  454.         case ISO_IOC_GETLOGSIZE:
  455.             return 1492;
  456. d33 1
  457. a33 1
  458.             return -EINVAL;
  459. d39 25
  460. @
  461.